completed-signal for coroutines with more than one yield#17291
Conversation
|
The error was probably related to me not storing references before. That's fixed now, but I'd still appreciate it if someone had a look and told me if I am handling the references correctly. |
There was a problem hiding this comment.
Godot's C++ code uses snake_case for all identifiers, should be previous_state.
|
Could you squash the commits together? Commits 2 and 3 are fixups of the first one, so we only need the final state. |
…ine now, allowing to yield for completion of a function with more than one yield inside.
|
If it's ok I would use the opportunity to remove the code duplication in that place. |
Yeah that would be nice :) |
|
Tested, the code makes sense, and I think the struggle is real :) Thanks! |
|
@hpvb Any chance this will be added in 3.0.3? |
|
Cherry picked into 3.0.3 |
This is a proposal in response to issue #17280.
You can yield for completion of a coroutine like this:
yield(coroutine(), "completed")but without this PR that only works for coroutines with one yield inside, since every yield keyword returns a GDScriptFunctionState and the completed-signal was only emitted for the last one.
NOTE: there's probably something missing yet - it causes an error that I don't quite understand (Object::disconnect warns that the signal "completed" didn't exist) and I assume that referencing the previous GDScriptFunctionStates with raw pointers may not be a good idea since it probably won't make sure that the previous states aren't freed before their completed-signal is emitted.